package org.yoki.edu.common.utils.geometry;

/**
 * @author Sky$
 * @Description: TODO
 * @date 2018/2/5$ 15:12$
 */
public class Circle {

    private Point p;

    private double r;

    public Circle(double x, double y, double r) {
        p = new Point(x, y);
        this.r = r;
    }

    public Circle(Point p, double r) {
        this.p = p;
        this.r = r;
    }

    public Point getPoint() {
        return p;
    }

    public double getX() {
        return p.getX();
    }

    public double getY() {
        return p.getY();
    }

    public double getR() {
        return r;
    }

    public static boolean isOnCircle(Circle c, Point p) {
        return isOnCircle(c.getPoint(), c.getR(), p);
    }

    public static boolean isOnCircle(Point rp, double r, Point p) {
        //(x − x0)^2 + (y − y0)^2 = r^2
        double d1 = Math.pow(p.getX() - rp.getX(), 2);
        double d2 = Math.pow(p.getY() - rp.getY(), 2);
        if ((d1 + d2) == Math.pow(r, 2)) {
            return true;
        }
        return false;
    }

}
